#include <iostream>
#include <string>
using namespace std;
#include "MyArray.hpp"

void printIntArray(MyArray<int>& arr1)
{
    for (int i = 0;i < arr1.getSize();i++)
    {
        cout << arr1[i] << " ";
    }
    cout << endl;
}

void test1()
{
    MyArray<int> arr1(5);

    //利用尾插法，向数组插入数据
    for (int i = 0;i < arr1.getCapacity();i++)
    {
        arr1.Push_Back(i);
    }
    cout << "arr1的打印输出为：" << endl;

    printIntArray(arr1);

    cout << "arr1的容量为：" << arr1.getCapacity() << endl;
    cout << "arr1的大小为：" << arr1.getSize() << endl;

    //利用尾删法
    MyArray<int> arr2(arr1);
    arr2.Pop_Back();
    cout << "尾删后：" << endl;
    cout << "arr2的容量为：" << arr2.getCapacity() << endl;
    cout << "arr2的大小为：" << arr2.getSize() << endl;

    cout << "arr2的打印输出为：" << endl;

    printIntArray(arr2);
}

//测试自定义数据类型
class Person
{
public:
    string name;
    int age;

    Person(){}
    Person(string name, int age)
    {
        this->name = name;
        this->age = age;
    }
};

void printPersonArray(MyArray<Person>& arr)
{
    for (int i = 0;i < arr.getSize();i++)
    {
        cout << "第" << i << "个人：" << endl;
        cout << "姓名：" << arr[i].name << endl;
        cout << "年龄：" << arr[i].age << endl;
    }
}

void test2()
{
    MyArray<Person> arr(10);

    Person p1("孙悟空", 999);
    Person p2("韩信", 20);
    Person p3("妲己", 19);
    Person p4("赵云", 35);
    Person p5("安琪拉", 24);

    //尾插法
    arr.Push_Back(p1);
    arr.Push_Back(p2);
    arr.Push_Back(p3);
    arr.Push_Back(p4);
    arr.Push_Back(p5);

    //打印数组
    printPersonArray(arr);

    //输出
    cout << "arr的容量为：" << arr.getCapacity() << endl;
    cout << "arr的大小为：" << arr.getSize() << endl;
}
int main()
{
    //test1();
    test2();
    return 0;
}